package com.lcf.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dao.SysBannerDao;
import com.lcf.system.dto.SysBannerDTO;
import com.lcf.system.entity.SysBanner;
import com.lcf.system.query.SysBannerPageQuery;
import com.lcf.system.service.SysBannerService;
import com.lcf.system.vo.SysBannerVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图(SysBanner)表服务实现类
 *
 * @author lcf
 * @since 2025-05-07 22:23:23
 */
@Service("sysBannerService")
public class SysBannerServiceImpl extends ServiceImpl<SysBannerDao, SysBanner> implements SysBannerService {

    @Override
    public void add(SysBannerDTO dto) {
        BeanUtil.copyProperties(dto, SysBanner.class).insert();
    }

    @Override
    public void edit(long id, SysBannerDTO dto) {
        SysBanner sysBanner = BeanUtil.copyProperties(dto, SysBanner.class);
        sysBanner.setId(id);
        sysBanner.updateById();
    }

    @Override
    public void delete(long id) {
        removeById(id);
    }

    @Override
    public PageVO<SysBannerVO> page(SysBannerPageQuery query) {
        Page<SysBanner> page = Db.lambdaQuery(SysBanner.class)
                .page(query.toPage());
        return new PageVO<>(page, SysBannerVO.class);
    }

    @Override
    public List<SysBannerVO> listAll() {
        return BeanUtil.copyToList(list(), SysBannerVO.class);
    }

    @Override
    public SysBannerVO get(long id) {
        return BeanUtil.copyProperties(getById(id), SysBannerVO.class);
    }
}

